package com.leetcode.dynamicplan;

import java.util.ArrayList;
import java.util.List;

/**
 * date:
 * description:
 */
public class Rob198 {

    public static int[] rob(int[] nums) {
        int len = nums.length;
//        if(nums == null || len == 0){
//            return 0;
//        }
//        if(len == 1){
//            return nums[0];
//        }
        int[] dp = new int[len];
        dp[0] = nums[0];
        dp[1] = Math.max(nums[0], nums[1]);
        for(int i = 2; i < len; i++){
            dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i]);
        }
        return dp;
    }

    public static void main(String[] args) {
//        int[] nums = new int[]{1,2,3,1};
        int[] nums = new int[]{2,7,9,3,1};
        int[] dp = rob(nums);
        int len = nums.length;
        boolean[] path = new boolean[len];
        for(int i = len - 1; i >= 2; i--){
            if(dp[i] == dp[i - 1]){
                path[i - 1] = true;
            }else{
                path[i] = true;
                path[i - 2] = true;
            }
        }
        List<Integer> res = new ArrayList<>();
        for(int i = 0; i < path.length; i++){
            if(path[i]){
                res.add(i + 1);
            }
        }
        System.out.println(res);
    }
}
